{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "567f77d0",
   "metadata": {},
   "source": [
    "# {func}`~tvm.instrument.pass_instrument`\n",
    "\n",
    "{func}`~tvm.instrument.pass_instrument` 为 pass 添加 instrument 装饰。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "1a53d6c2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import tvm\n",
    "@tvm.instrument.pass_instrument\n",
    "class SkipPass:\n",
    "    def __init__(self, skip_pass_name):\n",
    "        self.skip_pass_name = skip_pass_name\n",
    "\n",
    "    # Uncomment to customize\n",
    "    # def enter_pass_ctx(self):\n",
    "    #    pass\n",
    "\n",
    "    # Uncomment to customize\n",
    "    # def exit_pass_ctx(self):\n",
    "    #    pass\n",
    "\n",
    "    # If pass name contains keyword, skip it by return False. (return True: not skip)\n",
    "    def should_run(self, mod, pass_info):\n",
    "        if self.skip_pass_name in pass_info.name:\n",
    "            return False\n",
    "        return True\n",
    "\n",
    "    # Uncomment to customize\n",
    "    # def run_before_pass(self, mod, pass_info):\n",
    "    #    pass\n",
    "\n",
    "    # Uncomment to customize\n",
    "    # def run_after_pass(self, mod, pass_info):\n",
    "    #    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2a2d7046",
   "metadata": {},
   "outputs": [],
   "source": [
    "skip_annotate = SkipPass(\"AnnotateSpans\")\n",
    "with tvm.transform.PassContext(instruments=[skip_annotate]):\n",
    "    tvm.compile(mod, \"llvm\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py313",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
